package UIUtils
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;

	public class uif_complexState extends EventDispatcher {
		
		private var _states: Array;
		private var _data: Object;
		public function uif_complexState(states: String, target:IEventDispatcher=null, onComplete: Function =null) {
			super(target);
			_states = states.split(',');
			_data = new Object();
			if (onComplete != null) {
				function doComplete(e: Event):void {
					onComplete(e);
					removeEventListener(Event.COMPLETE, doComplete);
				}
				addEventListener(Event.COMPLETE, doComplete);
			}
		}
		
		public function stateReady(a_stateName: String, a_state: Object): void {
			_data[a_stateName] = a_state;
			for (var i: int = 0; i<_states.length; i++)
				if (!_data.hasOwnProperty(_states[i])) return;
			dispatchEvent(new Event(Event.COMPLETE));
		}
		
		public function get data(): Object {
			return _data; 
		}
	}
}